namespace Jsl.FxCop
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using Microsoft.FxCop.Sdk;

    /// <content>
    /// Holds the <see cref="TypeFieldUsage"/> inner class.
    /// </content>
    public partial class MarkFieldReadOnly
    {
        /// <summary>
        /// Holds information about field usage.
        /// </summary>
        private class TypeFieldUsage : Dictionary<TypeNode, FieldUsage>
        {
            /// <summary>
            /// Gets or creates the field usage if it hasn't already been created.
            /// </summary>
            /// <param name="type">The type to get the field usage of.</param>
            /// <returns>The field usage for the type.</returns>
            public FieldUsage GetFieldUsage(TypeNode type)
            {
                if (type == null)
                {
                    throw new ArgumentNullException("type");
                }

                Contract.EndContractBlock();

                FieldUsage fieldUsage;
                if (!this.TryGetValue(type, out fieldUsage))
                {
                    fieldUsage = new FieldUsage(type);
                    this.Add(type, fieldUsage);
                }

                return fieldUsage;
            }
        }
    }
}